package com.ruoyi.web.cp.schuedule;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.web.cp.service.WinxinService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author xiesm
 * @Description: TODO
 * @date 2025-07-24 15:12
 */
@Slf4j
@Component
public class HeartbeatTask {
    @Autowired
    private WinxinService winxinService;

    public void execute() {
        heartbeat("http://156.225.23.55/heartbeat", "中亿通");
        heartbeat("http://156.238.239.167/heartbeat", "华冠");
    }

    public void heartbeat(String url, String name) {
        String body = HttpUtil.get(url);
        log.info("{},{}", name, body);
        JSONObject jsonObject = JSONObject.parseObject(body);
        if (!"UP".equalsIgnoreCase(jsonObject.getString("status"))) {
            winxinService.sendTextMessage("1000004", name + "服务异常");
        }
    }
}
